package org.dawning.shop.category.repertory;

import org.dawning.shop.category.entity.BaseCategory;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource(path = "baseCategory",collectionResourceRel = "baseCategory")
public interface BaseCategoryRepository extends MongoRepository<BaseCategory,String>{

    BaseCategory findOneById(String id);

    List<BaseCategory> findAllByParentId(String pid);

    @Query("{ancestorIds:?0}")
    List<BaseCategory> findAllByAncestorIdsContaining(String pid);

}